package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.gigi.enums.ErrorCodeEnum;
import com.gigi.model.CountSignInRecordRequest;
import com.gigi.model.IdRequest;
import com.gigi.model.SignInRecordDO;
import com.gigi.model.StudentStatisticsDO;
import com.gigi.service.manual.SignInRecordManageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 考勤管理
 */
@RestController
@RequestMapping("sign-in-record-manage")
public class SignInRecordManageController {

    private final SignInRecordManageService signInRecordManageService;

    public SignInRecordManageController(SignInRecordManageService signInRecordManageService) {
        this.signInRecordManageService = signInRecordManageService;
    }

    @ApiOperation(value = "签到成功/请假通过/补签通过后修改考勤记录为正常")
    @PostMapping("/edit")
    public Response edit(@RequestBody @Valid SignInRecordDO request) {
        return signInRecordManageService.edit(request);
    }

    @ApiOperation(value = "教师端考勤统计")
    @PostMapping("/statistics")
    public MultiResponse<SignInRecordDO> statistics(@RequestBody @Valid IdRequest request) {
        return signInRecordManageService.statistics(request);
    }

    @ApiOperation(value = "学生端考勤统计")
    @PostMapping("/count")
    public SingleResponse<StudentStatisticsDO> count(@RequestBody @Valid CountSignInRecordRequest request) {
        return signInRecordManageService.count(request);
    }

    @ApiOperation(value = "导出考勤统计excel")
    @PostMapping("/excel")
    public Response excel(@RequestBody @Valid IdRequest request) {
        try {
            signInRecordManageService.excel(request);
        } catch (Exception e) {
            System.out.println(e);
            return Response.buildFailure(ErrorCodeEnum.BIZ_EXCEPTION.getErrCode(), e.getMessage());
        }
        return Response.buildSuccess();
    }


}
